import datetime
# 年，月，日
d = datetime.date(2024, 10, 1)
print(d)

import datetime
# 时，分，秒，毫秒
t = datetime.time(10, 20, 30, 40)
print(t)

from datetime import datetime

# 获取当前日期时间
now = datetime.now()
print(now)
print(type(now), end="\n\n")

# 获取当前日期
date = now.date()
print(date)
print(type(date), end="\n\n")

# 获取当前时间
time = now.time()
print(time)
print(type(time), end="\n\n")


from datetime import datetime

timestamp = datetime.now().timestamp()
print(timestamp)
print(type(timestamp))

from datetime import datetime

fromtimestamp = datetime.fromtimestamp(1732602531.607458)
print(fromtimestamp)
print(type(fromtimestamp))


from datetime import datetime

now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S"))
print(now.strftime("%y-%m-%d %I:%M:%S"))

from datetime import datetime

print(datetime.strptime("2024-01-02 10:20:30", "%Y-%m-%d %H:%M:%S"))

import datetime

now = datetime.datetime.now()
# 表示时间间隔：1天2小时10分钟
timedelta = datetime.timedelta(days=1, hours=2, minutes=10)
print(now)
print(now - timedelta)
print(now + timedelta)
print(type(timedelta))


import datetime

now = datetime.datetime.now()
date_time = datetime.datetime.strptime("2024-01-02 10:20:30", "%Y-%m-%d %H:%M:%S")
time_delta = now - date_time
print(time_delta)
print(type(time_delta))